package com.bnq.logc.utils

import android.os.Environment
import android.os.StatFs
import java.io.File


class StorageUtil {

    companion object{
        fun getSDTotalSize(): Long {
            /*获取存储卡路径*/
            val sdcardDir: File = Environment.getExternalStorageDirectory()
            /*StatFs 看文件系统空间使用情况*/
            val statFs = StatFs(sdcardDir.getPath())
            val blockSize = statFs.blockSizeLong
            val totalSize = statFs.blockCountLong
            return blockSize * totalSize
        }

        /**
         * 获得sd卡剩余容量，即可以大小
         * @return
         */
        fun getSdAvailableSize(): Long {
            val path = Environment.getExternalStorageDirectory()
            val statFs = StatFs(path.path)
            val blockSize = statFs.blockSizeLong
            val availableBlocks = statFs.availableBlocksLong
            return blockSize * availableBlocks
        }

        /**
         * 获得机身内存大小
         * @return
         */
        fun getRomTotalSize(): Long {
            val path = Environment.getDataDirectory()
            val statFs = StatFs(path.path)
            val blockSize = statFs.blockSizeLong
            val tatalBlocks = statFs.blockCountLong
            return blockSize * tatalBlocks
        }

        /**
         * 获得机身可用内存
         * @return
         */
         fun getRomAvailableSize(): Long {
            val path = Environment.getDataDirectory()
            val statFs = StatFs(path.path)
            val blockSize = statFs.blockSizeLong
            val availableBlocks = statFs.availableBlocksLong
            return blockSize * availableBlocks
        }
    }

}